package com.smilive.delay.queue.netty;

import io.netty.util.Timeout;
import io.netty.util.TimerTask;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

/**
 * @program: delay_queue_start
 * @Date: 2022-02-08 14:27
 * @Author: smilive
 * @Description:
 */
public class NettyDealyTask implements TimerTask {

    private static final DateTimeFormatter F = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    /**
     * 任务 ID
     */
    private final long taskId;

    /**
     * 创建时间戳
     */
    private final long timestamp;

    public NettyDealyTask(long taskId) {
        this.taskId = taskId;
        this.timestamp = System.currentTimeMillis();
    }

    @Override
    public void run(Timeout timeout) {
        System.out.println(String.format("任务执行时间:%s,任务创建时间:%s,任务ID:%s",
                LocalDateTime.now().format(F), LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()).format(F), taskId));
    }
}
